import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter001/router/BigShowBigImageView.dart';
import 'package:flutter001/router/NamedRouter.dart';
import 'package:flutter001/state/TextStatePageWidget.dart';

void main() {
  runApp(MaterialApp(
    title: "嵌套widget",
    home: Scaffold(
      appBar: AppBar(
        title: const Text('Welcome to Flutter'),
      ),
      body: const NestWidgetClass(),
    ),
    routes: NamedRouter.initRoutes(),
  ));
}

class NestWidgetClass extends StatelessWidget {
  const NestWidgetClass({Key? key}) : super(key: key);

  _toast() {
    Fluttertoast.showToast(
        msg: "This is Center Short Toast",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.red,
        textColor: Colors.white,
        fontSize: 16.0);
  }


  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: const [
            Text("123"),
            Expanded(
              child: Text("456",
                  textAlign: TextAlign.center,
                  style: TextStyle(color: Colors.green, fontSize: 60)),
            )
          ],
        ),
        Column(
          children: [
            Center(
              child: RaisedButton(
                  child: const Text("居中按钮"),
                  textColor: Colors.blue,
                  onPressed: _toast),
            ),
            const Icon(Icons.favorite, color: Colors.red),
            GestureDetector(
                child: Image.asset('images/img001.jpg', width: 100,
                    height: 100,
                    fit: BoxFit.cover),
                onTap: () {
                  Navigator.push(context, MaterialPageRoute(builder: (_) {
                    return BigShowBigImageView();
                  }));
                }
            ),
            GestureDetector(
              child: Center(
                child: Hero(
                  tag: "img",
                  child: Image.network(
                      "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242332225H9-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651286080&t=a4306e2d9e190ba4a76e2e5ff97edae9",
                      width: 100,
                      height: 100,
                  )
                ),
              ),
              onTap: () {
                Navigator.push(context, MaterialPageRoute(builder: (_) {
                  return BigHeroImage();
                }));
              },
            ),
            Center(
              child: Row(
                children: [
                  Container(
                    child: MaterialButton(
                      onPressed: () {
                        Navigator.pushNamed(context, '/first');
                      },
                      shape: RoundedRectangleBorder(
                          side: const BorderSide(color: Colors.red,
                              width: 2),
                          borderRadius: BorderRadius.circular(10)
                      ),
                      padding: const EdgeInsets.all(4),
                      child: Text("oFirstRouter"),
                    ),
                    padding: const EdgeInsets.symmetric(
                        vertical: 4.0,
                        horizontal: 8.0
                    ),
                    color: Colors.green,
                  ),
                  TextStatePage()
                ],
              ),
            ),
            MaterialButton(
                child: const Text("home page"),
                onPressed: () {
                  _goToHome(context);
                }),
          ],
        )
      ],
    );
  }

  _goToHome(BuildContext context) {
    Navigator.pushNamed(context, '/third');
  }
}
